package 力扣日常刷题.木22二月.第04天210;
import 力扣日常刷题.Node;

/**
 * @author 帅小伙
 * @date 2022/2/11
 * @description
 */
public class Demo37二叉搜索树与双向链表2 {

    Node pre,head;
    public Node treeToDoublyList(Node root) {
        if(root == null) return null;
        dfs(root);
        head.left = pre;
        pre.right = head;
        return head;
    }

    public void dfs(Node cur) {
        if(cur == null) return;
        dfs(cur.left);
        if(pre == null)head = cur;
        else pre.right = cur;
        cur.left = pre;
        pre = cur;
        dfs(cur.right);
    }



}
